package com.myproject
{
	import fr.digitas.flowearth.conf.Conf;
	import flash.events.ProgressEvent;
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.Event;


	/**
	 * @author Thibault Loup - Cloneoner.com
	 */
	public class Preloader extends Sprite
	{

		// __________________________________________________________
		// -										 	  CONSTRUCTOR
		public function Preloader()
		{
			if (stage) _init();
			else addEventListener(Event.ADDED_TO_STAGE, _init);
		}

		private function _init(event : Event = null) : void
		{
			trace("init");
			
			stage.scaleMode = StageScaleMode.NO_SCALE;
			stage.align = StageAlign.TOP_LEFT;
			
			loaderInfo.addEventListener( ProgressEvent.PROGRESS, _selfProgress );
		}

		private function _selfProgress(event : ProgressEvent) : void
		{
			trace("load : " + (loaderInfo.bytesLoaded / loaderInfo.bytesTotal));
			
			if( (loaderInfo.bytesLoaded / loaderInfo.bytesTotal) == 1)
				_loadConf();
		}

		// __________________________________________________________
		// -										 		   EVENTS

		private function _onConfComplete(event : Event) : void
		{
			trace("confLoaded");
			
			trace(Conf.getDatas("test"));
		}


		// __________________________________________________________
		// -										 PRIVATES METHODS

		private function _loadConf() : void
		{
			trace(" loadConf");
			
			Conf.addEventListener( Event.COMPLETE, _onConfComplete );
			Conf.grabParam( loaderInfo );
			Conf.setProperty( 'confFile', 'loca/xml/conf.xml' );
			Conf.loadXml( Conf.getURLRequest( 'confFile' ) );
		}
	}
}
